package com.xrit.sunnyday.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.xrit.sunnyday.pojo.Permission;
import com.xrit.sunnyday.service.PermissionService;
import com.xrit.sunnyday.common.MessageConstant;
import com.xrit.sunnyday.common.PageResult;
import com.xrit.sunnyday.common.QueryPageBean;
import com.xrit.sunnyday.common.Result;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/permission")
public class PermissionController {
    /*
    远程调用
     */
    @Reference
    private PermissionService permissionService;
    /*
    查询所有并分页
     */
    @RequestMapping("/findPage.do")
    public Result findPage(@RequestBody QueryPageBean queryPageBean){
        PageResult page = permissionService.findPage(queryPageBean);
        return new Result(true, MessageConstant.QUERY_PERMISSION_SUCCESS,page);
    }
    /*
    添加权限
     */
    @RequestMapping("/add.do")
    public Result add(@RequestBody Permission permission){
        permissionService.add(permission);
        return new Result(true,MessageConstant.ADD_PERMISSION_SUCCESS);
    }
    /*
    根据id删除权限
     */
    @RequestMapping("/delete.do")
    public Result deleteById(Integer id){
        permissionService.deleteById(id);
        return new Result(true,MessageConstant.DELETE_PERMISSION_SUCCESS);
    }
    /*
    根据id查询权限
     */
    @RequestMapping("/findById.do")
    public Result findById(Integer id){
        Permission permission = permissionService.findById(id);
        return new Result(true,MessageConstant.QUERY_PERMISSION_SUCCESS,permission);
    }
    /*
    根据id修改
     */
    @RequestMapping("/update.do")
    public Result update(@RequestBody Permission permission){
        permissionService.update(permission);
        return new Result(true,MessageConstant.UPDATE_PERMISSION_SUCCESS);
    }
}
